package com.snowy.hidden.user.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.snowy.hidden.user.domain.dto.AppInfoDTO;
import com.snowy.hidden.user.domain.model.AppInfo;
import com.snowy.hidden.user.mapper.AppInfoMapper;
import com.snowy.hidden.user.service.AppInfoService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * APP版本管理(AppInfo)表服务实现类
 *
 * @author chenli
 * @since 2022-01-08 20:07:01
 */
@Service("appInfoService")
public class AppInfoServiceImpl extends ServiceImpl<AppInfoMapper, AppInfo> implements AppInfoService {

    @Resource
    private AppInfoMapper appInfoMapper;


    @Override
    public AppInfoDTO getVersionName(Integer type) {
        LambdaQueryWrapper<AppInfo> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(AppInfo::getType,type);
        lambdaQueryWrapper.orderByDesc(AppInfo::getCreateTime);
        lambdaQueryWrapper.last("limit 0,1");
        AppInfo appInfo = appInfoMapper.selectOne(lambdaQueryWrapper);
        AppInfoDTO appInfoDTO=new AppInfoDTO();
        if (ObjectUtil.isNotEmpty(appInfo)) {
            BeanUtils.copyProperties(appInfo, appInfoDTO);
        }
        return appInfoDTO;
    }
}
